import { Session } from "../../../Engine/RMI/Session";
import { Communicator } from "../../../Engine/RMI/Communicator";
import { CommunicatorManager } from "../../../Engine/RMI/CommunicatorManager";
import { GroupProtocol } from "../../../Framework/Protocol/CDFProtocol/GroupProtocol";
import { Protocol } from "../../../Framework/Protocol/CDFProtocol/Protocol";
// import { FrameUtil } from "../../../com/gengine/core/FrameUtil";
import { RMIProxyObject } from "../../../Engine/RMI/RMIProxyObject";
import { DataEvent } from "../../../flash/events";
//class RMISession

export class RMISession {
  public get session(): Session {
    return this._session;
  }

  public set url(arg1: string) {
    if (this._url != arg1) {
      this._url = arg1;
      this._session = new Session();
      this.createCommunicator();
      this._session.bindCommunicator(this._comm);
    }
    return;
  }

  public get url(): string {
    return this._url;
  }

  protected createCommunicator() {
    this._comm = CommunicatorManager.getInstance().createCommunicator(
      this._url,
      new GroupProtocol(new Protocol())
    );
    this._comm.connection.addEventListener(
      "网络数据处理时间",
      this.onTestNetCommandTime.bind(this)
    );
    return this._comm;
  }

  /* internal  */ onTestNetCommandTime(
    arg1: DataEvent /* flash.events.DataEvent */
  ): void {
    // var loc1 = parseInt(arg1.data);
    // FrameUtil.messageProTimer = FrameUtil.messageProTimer + loc1;
    return;
  }

  public registerProxy(arg1: RMIProxyObject): void {
    arg1.bindingSession(this._session);
    return;
  }

  private /* var */ _session!: Session;

  private /* var */ _url!: string;

  private /* var */ _comm!: Communicator;
}
